package org.gdstash.ui;

import org.gdstash.db.DBStashItem;
import org.gdstash.ui.util.AdjustablePanel;
import org.gdstash.util.GDColor;
import org.gdstash.util.GDMsgFormatter;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;

public class GDItemInfoSimilarPaneAlt extends AdjustablePanel {
    private JLabel lblItemCombo;
    private JLabel lblItemPrefix;
    private JLabel lblItemSuffix;
    private JLabel lblClassCombo;
    private JLabel txtItemCombo;
    private JLabel txtItemPrefix;
    private JLabel txtItemPrefixLevel;
    private JLabel txtItemSuffix;
    private JLabel txtItemSuffixLevel;
    private JLabel txtClassCombo;

    public GDItemInfoSimilarPaneAlt() {
        this.adjustUI();
        GroupLayout layout = null;
        GroupLayout.SequentialGroup hGroup = null;
        GroupLayout.SequentialGroup vGroup = null;
        final Border lowered = BorderFactory.createEtchedBorder(1);
        final Border raised = BorderFactory.createEtchedBorder(0);
        final Border compound = BorderFactory.createCompoundBorder(raised, lowered);
        layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(false);
        hGroup = layout.createSequentialGroup();
        hGroup.addGroup(layout.createParallelGroup().addComponent(this.lblItemCombo)).addGroup(layout.createParallelGroup().addComponent(this.txtItemCombo)).addGroup(layout.createParallelGroup().addComponent(this.lblClassCombo)).addGroup(layout.createParallelGroup().addComponent(this.txtClassCombo)).addGroup(layout.createParallelGroup().addComponent(this.lblItemPrefix)).addGroup(layout.createParallelGroup().addComponent(this.txtItemPrefix)).addGroup(layout.createParallelGroup().addComponent(this.txtItemPrefixLevel)).addGroup(layout.createParallelGroup().addComponent(this.lblItemSuffix)).addGroup(layout.createParallelGroup().addComponent(this.txtItemSuffix)).addGroup(layout.createParallelGroup().addComponent(this.txtItemSuffixLevel));
        layout.setHorizontalGroup(hGroup);
        vGroup = layout.createSequentialGroup();
        vGroup.addGroup(layout.createParallelGroup().addComponent(this.lblItemCombo).addComponent(this.txtItemCombo).addComponent(this.lblClassCombo).addComponent(this.txtClassCombo).addComponent(this.lblItemPrefix).addComponent(this.txtItemPrefix).addComponent(this.txtItemPrefixLevel).addComponent(this.lblItemSuffix).addComponent(this.txtItemSuffix).addComponent(this.txtItemSuffixLevel));
        layout.setVerticalGroup(vGroup);
        layout.linkSize(0, this.lblItemCombo, this.lblClassCombo);
        layout.linkSize(0, this.lblItemCombo, this.lblItemPrefix);
        layout.linkSize(0, this.lblItemCombo, this.lblItemSuffix);
        layout.linkSize(0, this.txtItemCombo, this.txtClassCombo);
        layout.linkSize(0, this.txtItemCombo, this.txtItemPrefix);
        layout.linkSize(0, this.txtItemCombo, this.txtItemPrefixLevel);
        layout.linkSize(0, this.txtItemCombo, this.txtItemSuffix);
        layout.linkSize(0, this.txtItemCombo, this.txtItemSuffixLevel);
        layout.linkSize(1, this.lblItemCombo, this.lblClassCombo);
        layout.linkSize(1, this.lblItemCombo, this.lblItemPrefix);
        layout.linkSize(1, this.lblItemCombo, this.lblItemSuffix);
        layout.linkSize(1, this.lblItemCombo, this.txtItemCombo);
        layout.linkSize(1, this.lblItemCombo, this.txtClassCombo);
        layout.linkSize(1, this.lblItemCombo, this.txtItemPrefix);
        layout.linkSize(1, this.lblItemCombo, this.txtItemPrefixLevel);
        layout.linkSize(1, this.lblItemCombo, this.txtItemSuffix);
        layout.linkSize(1, this.lblItemCombo, this.txtItemSuffixLevel);
    }

    @Override
    public void adjustUI() {
        int size = 12;
        if (GDStashFrame.iniConfig != null) {
            size = GDStashFrame.iniConfig.sectUI.fontSize;
        }
        final Dimension dimMax = new Dimension(4 * size, 2 * size);
        Font fntLabel = UIManager.getDefaults().getFont("Label.font");
        fntLabel = fntLabel.deriveFont((float) size);
        Border border = null;
        if (this.txtItemCombo == null || this.txtItemPrefix == null || this.txtItemSuffix == null || this.txtClassCombo == null) {
            border = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
        }
        if (this.lblItemCombo == null) {
            this.lblItemCombo = new JLabel();
        }
        this.lblItemCombo.setText(GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_NUM_ITEM"));
        this.lblItemCombo.setFont(fntLabel);
        if (this.txtItemCombo == null) {
            (this.txtItemCombo = new JLabel()).setBorder(border);
        }
        this.txtItemCombo.setFont(fntLabel);
        this.txtItemCombo.setPreferredSize(dimMax);
        this.txtItemCombo.setMaximumSize(dimMax);
        if (this.lblClassCombo == null) {
            this.lblClassCombo = new JLabel();
        }
        this.lblClassCombo.setText(GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_NUM_ITEM_CLASS"));
        this.lblClassCombo.setFont(fntLabel);
        if (this.txtClassCombo == null) {
            (this.txtClassCombo = new JLabel()).setBorder(border);
        }
        this.txtClassCombo.setFont(fntLabel);
        if (this.lblItemPrefix == null) {
            this.lblItemPrefix = new JLabel();
        }
        this.lblItemPrefix.setText(GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_NUM_PREFIX"));
        this.lblItemPrefix.setFont(fntLabel);
        if (this.txtItemPrefix == null) {
            (this.txtItemPrefix = new JLabel()).setBorder(border);
        }
        this.txtItemPrefix.setFont(fntLabel);
        if (this.txtItemPrefixLevel == null) {
            (this.txtItemPrefixLevel = new JLabel()).setBorder(border);
        }
        this.txtItemPrefixLevel.setFont(fntLabel);
        if (this.lblItemSuffix == null) {
            this.lblItemSuffix = new JLabel();
        }
        this.lblItemSuffix.setText(GDMsgFormatter.getString(GDMsgFormatter.rbUI, "TXT_NUM_SUFFIX"));
        this.lblItemSuffix.setFont(fntLabel);
        if (this.txtItemSuffix == null) {
            (this.txtItemSuffix = new JLabel()).setBorder(border);
        }
        this.txtItemSuffix.setFont(fntLabel);
        if (this.txtItemSuffixLevel == null) {
            (this.txtItemSuffixLevel = new JLabel()).setBorder(border);
        }
        this.txtItemSuffixLevel.setFont(fntLabel);
    }

    public void setInfo(final DBStashItem.DuplicateInfo info) {
        if (info == null) {
            this.lblItemCombo.setForeground(GDColor.COLOR_FG_COMMON);
            this.lblItemPrefix.setForeground(GDColor.COLOR_FG_COMMON);
            this.lblItemSuffix.setForeground(GDColor.COLOR_FG_COMMON);
            this.lblItemSuffix.setForeground(GDColor.COLOR_FG_COMMON);
            this.txtItemCombo.setForeground(GDColor.COLOR_FG_COMMON);
            this.txtClassCombo.setForeground(GDColor.COLOR_FG_COMMON);
            this.txtItemPrefix.setForeground(GDColor.COLOR_FG_COMMON);
            this.txtItemPrefixLevel.setForeground(GDColor.COLOR_FG_COMMON);
            this.txtItemSuffix.setForeground(GDColor.COLOR_FG_COMMON);
            this.txtItemSuffixLevel.setForeground(GDColor.COLOR_FG_COMMON);
            this.txtItemCombo.setText("");
            this.txtClassCombo.setText("");
            this.txtItemPrefix.setText("");
            this.txtItemPrefixLevel.setText("");
            this.txtItemSuffix.setText("");
            this.txtItemSuffixLevel.setText("");
        } else {
            this.lblItemCombo.setForeground(info.numItemCombo.foreground);
            this.lblItemPrefix.setForeground(info.numItemPrefix.foreground);
            this.lblItemSuffix.setForeground(info.numItemSuffix.foreground);
            this.lblItemSuffix.setForeground(info.numItemSuffix.foreground);
            this.txtItemCombo.setForeground(info.numItemCombo.foreground);
            this.txtClassCombo.setForeground(info.numClassCombo.foreground);
            this.txtItemPrefix.setForeground(info.numItemPrefix.foreground);
            this.txtItemPrefixLevel.setForeground(info.levelItemPrefix.foreground);
            this.txtItemSuffix.setForeground(info.numItemSuffix.foreground);
            this.txtItemSuffixLevel.setForeground(info.levelItemSuffix.foreground);
            this.txtItemCombo.setText(info.numItemCombo.text);
            this.txtClassCombo.setText(info.numClassCombo.text);
            this.txtItemPrefix.setText(info.numItemPrefix.text);
            this.txtItemPrefixLevel.setText(info.levelItemPrefix.text);
            this.txtItemSuffix.setText(info.numItemSuffix.text);
            this.txtItemSuffixLevel.setText(info.levelItemSuffix.text);
        }
    }
}
